package com.crm.system.service.impl.csd.customerManager;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.common.model.Enum.csd.CustomerDataStatusEnum;
import com.crm.common.model.Enum.csd.CustomerEnum;
import com.crm.common.model.Enum.csd.FinishOrderProductEnum;
import com.crm.common.model.Enum.csd.WorkLogEnum;
import com.crm.common.util.CommonUtils;
import com.crm.common.util.DateUtil;
import com.crm.model.entity.common.Dictionary;
import com.crm.model.entity.csd.customerManager.*;
import com.crm.model.entity.customerManager.*;
import com.crm.model.entity.finishOrderProduct.FinishOrderProduct;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.entity.sys.permissionManagement.SysCompany;
import com.crm.model.qo.csd.customerManager.CustomerInfoQO;
import com.crm.model.qo.csd.customerManager.CustomerQO;
import com.crm.model.qo.csd.customerManager.CustomerUpdateQO;
import com.crm.model.vo.csd.customerManager.*;
import com.crm.model.vo.orderManager.CustomerProductOrderVO;
import com.crm.service.common.DictionaryDbService;
import com.crm.service.contactManager.ContactDbService;
import com.crm.service.contractManager.CustomerContractDbService;
import com.crm.service.csd.customerManager.CustomerDbService;
import com.crm.service.csd.customerManager.CustomerMemberCardDetailDbService;
import com.crm.service.customerManager.*;
import com.crm.service.finishOrderProductManager.FinishOrderProductDbService;
import com.crm.service.opportunityManager.OpportunityDbService;
import com.crm.service.orderManager.CustomerProductOrderDbService;
import com.crm.service.sys.permissionManagement.SysCompanyDbService;
import com.crm.system.service.csd.customerManager.CustomerService;
import com.crm.system.service.csd.customerManager.CustomerServiceWorkLogService;
import com.crm.system.service.customerManager.CustomerReturnService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author yincuimei
 * @Date 2021/7/23 11:27
 */
@Service("csdCustomerServiceImpl")
@Slf4j
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerDbService customerDbService;

    @Autowired
    private DictionaryDbService dictionaryDbService;

    @Autowired
    private CustomerReturnService customerReturnService;

    @Autowired
    private CustomerReceiveDbService customerReceiveDbService;

    @Autowired
    private CustomerContactPersonDbService contactPersonDbService;

    @Autowired
    private ContactDbService contactDbService;

    @Autowired
    private OpportunityDbService opportunityDbService;

    @Autowired
    private CustomerServiceWorkLogService workLogService;

    @Autowired
    private CustomerMemberCardDetailDbService customerMemberCardDetailDbService;

    @Autowired
    private CustomerContractDbService customerContractDbService;

    @Autowired
    private SysCompanyDbService sysCompanyDbService;

    @Autowired
    private CustomerProductDetailMemberCardDbService customerProductDetailMemberCardDbService;

    @Autowired
    private CustomerSendCodeDbService customerSendCodeDbService;

    @Autowired
    private FinishOrderProductDbService finishOrderProductDbService;

    @Autowired
    private CustomerProductOrderDbService customerProductOrderDbService;

    /**
     * 客户列表
     * @param customerQO --查询条件
     * @param pageIndex  --页码
     * @param pageSize   --分页大小
     * @param sortName   --排序字段
     * @param sortOrder  --排序规则
     * @author yincuimei
     * @return
     */
    @Override
    public DhPageInfo<CustomerVO> selectCustomerVOList(CustomerQO customerQO, Integer pageIndex, Integer pageSize, String sortName, String sortOrder) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        //排序
        StringBuilder order = new StringBuilder();
        if (!StringUtils.isBlank(sortName) && !StringUtils.isBlank(sortOrder)) {
            switch (sortName) {
                case "createTm": {
                    order.append("t.create_tm ").append(sortOrder);//创建时间
                }
                break;
                default:
                    break;
            }
        }
        List<CustomerVO> customerVOList = customerDbService.selectCustomerVOList(customerQO,order.toString());
        PageInfo<CustomerVO> pageInfo = new PageInfo<CustomerVO>(customerVOList);
        return new DhPageInfo<CustomerVO>(pageInfo, customerVOList);
    }

    /**
     * 会员客户列表
     * @param customerQO --查询条件
     * @param pageIndex  --页码
     * @param pageSize   --分页大小
     * @param sortName   --排序字段
     * @param sortOrder  --排序规则
     * @author wangpeng
     * @return
     */
    @Override
    public DhPageInfo<CustomerVO> selectCustomerMemberList(CustomerQO customerQO, Integer pageIndex, Integer pageSize, String sortName, String sortOrder) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        //排序
        StringBuilder order = new StringBuilder();
        if (!StringUtils.isBlank(sortName) && !StringUtils.isBlank(sortOrder)) {
            switch (sortName) {
                case "createTm": {
                    order.append("t.create_tm ").append(sortOrder);//创建时间
                }
                break;
                default:
                    break;
            }
        }
        List<CustomerVO> customerVOList = customerDbService.selectCustomerMemberList(customerQO,order.toString());
        PageInfo<CustomerVO> pageInfo = new PageInfo<CustomerVO>(customerVOList);
        return new DhPageInfo<CustomerVO>(pageInfo, customerVOList);
    }

    /**
     * 非会员客户列表
     * @param customerQO --查询条件
     * @param pageIndex  --页码
     * @param pageSize   --分页大小
     * @param sortName   --排序字段
     * @param sortOrder  --排序规则
     * @author wangpeng
     * @return
     */
    @Override
    public DhPageInfo<CustomerVO> selectCustomerNonMemberList(CustomerQO customerQO, Integer pageIndex, Integer pageSize, String sortName, String sortOrder) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        //排序
        StringBuilder order = new StringBuilder();
        if (!StringUtils.isBlank(sortName) && !StringUtils.isBlank(sortOrder)) {
            switch (sortName) {
                case "createTm": {
                    order.append("t.create_tm ").append(sortOrder);//创建时间
                }
                break;
                default:
                    break;
            }
        }
        List<CustomerVO> customerVOList = customerDbService.selectCustomerNonMemberList(customerQO,order.toString());
        PageInfo<CustomerVO> pageInfo = new PageInfo<CustomerVO>(customerVOList);
        return new DhPageInfo<CustomerVO>(pageInfo, customerVOList);
    }

    /**
     * 客户详情(企业客户)
     * @param customerId --客户ID
     * @author yincuimei
     * @return
     */
    @Override
    public CustomerDetailVO selectCustomerDetailVO(String customerId) {
        CustomerDetailVO customerDetailVO = customerDbService.selectCustomerDetailVO(customerId);
        if(customerDetailVO != null){
            String enterpriseState = customerDetailVO.getEnterpriseState();
            if(!StringUtils.isBlank(enterpriseState)){//企业状态从字典表查
                Dictionary dictionary = dictionaryDbService.selectDictionaryByOne("1",customerDetailVO.getEnterpriseState());
                if(dictionary != null && !StringUtils.isBlank(dictionary.getDictName())){
                    customerDetailVO.setEnterpriseStateText(dictionary.getDictName());
                }
            }
            Integer membershipLevel = customerDetailVO.getMembershipLevel();
            if(membershipLevel != null){//会员等级格式化(0:非会员客户;1:VIP1;2:VIP2;3:VIP3;4:VIP4;5:VIP5)
                switch (membershipLevel) {
                    case 0:
                        customerDetailVO.setMembershipLevelText("非会员客户");
                        break;
                    case 1:
                        customerDetailVO.setMembershipLevelText("VIP1");
                        break;
                    case 2:
                        customerDetailVO.setMembershipLevelText("VIP2");
                        break;
                    case 3:
                        customerDetailVO.setMembershipLevelText("VIP3");
                        break;
                    case 4:
                        customerDetailVO.setMembershipLevelText("VIP4");
                        break;
                    case 5:
                        customerDetailVO.setMembershipLevelText("VIP5");
                        break;
                    default:
                        break;
                }
            }
        }
        return customerDetailVO;
    }

    /**
     * 客户编辑(企业客户)
     * @param customerUpdateQO
     * @author yincuimei
     * @return
     */
    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public Boolean updateCustomerByCustomerId(CustomerUpdateQO customerUpdateQO) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//获取登录人信息
        String accountId = userAccount.getAccountId();
        String userName = userAccount.getUserName();
        if(customerUpdateQO != null){
            String customerId = customerUpdateQO.getCustomerId();//客户主键
            String companyId = customerUpdateQO.getCompanyId();//所属分公司
            String ownerPeopleId = customerUpdateQO.getOwnerPeopleId();//所有人
            //1.从数据库查出当前客户信息
            CustomerDetailVO customerDetailVO = customerDbService.selectCustomerDetailVO(customerId);

            //3-1.判断所有人是否为空,为空的话将客户收回(同管理端客户收回)
            if(StringUtils.isBlank(customerUpdateQO.getOwnerPeopleId())){//客户所有人为空
                String returnReason = userAccount.getUserName() + "将客户收回";
                retrieveCustomer(accountId,customerId,returnReason);
                companyId = "";
                ownerPeopleId = "";
            }else{//3-2. 新增领取记录(chs_customer_receive)
                CustomerReceive customerReceive = new CustomerReceive();
                customerReceive.setCustomerReceiveId(CommonUtils.getGUID());//主键
                customerReceive.setReceivePeopleId(ownerPeopleId);//分配人
                customerReceive.setReceiveTm(new Date());//分配时间
                customerReceive.setCustomerPoolFromId(customerDetailVO.getCustomerPoolId());
                customerReceive.setReceiveWay(2);//领取方式：1-领取；2:分配
                customerReceive.setCustomerId(customerId);//客户ID
                customerReceiveDbService.insertCustomerReceive(customerReceive);
            }

            //4.修改客户联系人表(chs_customer_contact_person)
            CustomerContactPerson customerContactPerson = new CustomerContactPerson();
            customerContactPerson.setUpdatePeopleId(accountId);//所有人
            customerContactPerson.setCompanyId(companyId);//所属公司
            customerContactPerson.setUpdateTm(new Date());//更新时间
            contactPersonDbService.updateCustomerPersonByCustomerId(customerContactPerson,customerId);

            //5.修改联系人表(lxr_contact)
            contactDbService.updateContactByCustomerId(customerId, ownerPeopleId, companyId, accountId, new Date());

            //6.修改商机表(sj_opportunity)
            opportunityDbService.updateOpportunityByCustomerId(customerId,ownerPeopleId,companyId,accountId,new Date());

            //7.新增工作日志(csd_work_log)
            List<CustomerServiceWorkLog> workLogList = new ArrayList<CustomerServiceWorkLog>();
            //7-1:数据库中的客户信息和当前修改的客户信息做对比,针对修改的字段记录到工作日志表
            if(customerDetailVO != null){
                Short logType = WorkLogEnum.LOG_TYPE_CUSTOMER.getCode().shortValue();//日志类型
                String logRemark = customerUpdateQO.getLogRemark() + "  "+ userAccount.getUserName();//备注
                if(!(customerUpdateQO.getCustomerName() != null? customerUpdateQO.getCustomerName(): "" ).equals(customerDetailVO.getCustomerName())){//修改了客户名
                    //拼接日志内容
                    String logContent = getLogContent(userName,"将客户名'",customerDetailVO.getCustomerName(),customerUpdateQO.getCustomerName());
                    CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(accountId,customerId,logType,logContent,logRemark);
                    workLogList.add(customerServiceWorkLog);
                }
                if(customerUpdateQO.getMembershipLevel()!=(customerDetailVO.getMembershipLevel())){//修改了会员等级
                    String logContent = getLogContent(userName,"将会员等级'",CustomerEnum.getMessage(customerDetailVO.getMembershipLevel()),CustomerEnum.getMessage(customerUpdateQO.getMembershipLevel()));
                    CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(accountId,customerId,logType,logContent,logRemark);
                    workLogList.add(customerServiceWorkLog);
                }
                if(!(customerUpdateQO.getCompanyId() != null ? customerUpdateQO.getCompanyId():"").equals(customerDetailVO.getCompanyId())){//修改了所属分公司
                    if(!StringUtils.isBlank(customerUpdateQO.getCompanyId()) || !StringUtils.isBlank(customerDetailVO.getCompanyId())){
                        String logContent = getLogContent(userName,"将所属分公司'",customerDetailVO.getCompanyName(),customerUpdateQO.getCompanyName());
                        CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(accountId,customerId,logType,logContent,logRemark);
                        workLogList.add(customerServiceWorkLog);
                    }
                }
                if(!(customerUpdateQO.getOwnerPeopleId()!= null ? customerUpdateQO.getOwnerPeopleId():"") .equals(customerDetailVO.getOwnerPeopleId())){//修改了所有人
                    if(!StringUtils.isBlank(customerUpdateQO.getOwnerPeopleId()) || !StringUtils.isBlank(customerDetailVO.getOwnerPeopleId())){
                        String logContent = getLogContent(userName,"将所有人'",customerDetailVO.getOwnerName(),customerUpdateQO.getOwnerPeopleName());
                        CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(accountId,customerId,logType,logContent,logRemark);
                        workLogList.add(customerServiceWorkLog);
                    }
                }

                Date membershipStartTm = customerUpdateQO.getMembershipStartTm();//会员开始时间
                Date membershipExpirationTm = customerUpdateQO.getMembershipExpirationTm();//会员结束时间
                if(membershipStartTm != null && membershipExpirationTm != null){
                    if(membershipStartTm !=(customerDetailVO.getMembershipStartTm()) ||
                            customerUpdateQO.getMembershipExpirationTm()!= (customerDetailVO.getMembershipExpirationTm())){//修改了会员起止日期
                        //根据客户ID查询合同表中的开始日期和结束日期(取合同表的合同起止日期【条件:合同状态为生效中,合同类型为会员合同的】)
                        List<Map<String,Date>> contractStartAndEndDateMap = customerContractDbService.selectCustomerContractByCustomerId(customerId);
                        if(contractStartAndEndDateMap != null && contractStartAndEndDateMap.size() > 0){
                            //页面传过来的会员起止日期和合同表中的开始和结束日期对比开始日期取最早的,结束日期取最晚的
                            for(Map<String,Date> dateMap : contractStartAndEndDateMap){
                                Date contractStartDate = null;
                                Date contractEndDate = null;
                                if(dateMap != null){
                                    contractStartDate = dateMap.get("contractStartDate");
                                    contractEndDate = dateMap.get("contractEndDate");
                                }

                               if(contractStartDate != null && contractStartDate.before(membershipStartTm)){
                                   membershipStartTm = contractStartDate;
                               }
                               if(contractEndDate != null && contractEndDate.after(membershipExpirationTm)){
                                   membershipExpirationTm = contractEndDate;
                               }
                            }
                        }
                        customerUpdateQO.setMembershipStartTm(membershipStartTm);
                        customerUpdateQO.setMembershipExpirationTm(membershipExpirationTm);

                        String membershipStartTmStr = "";
                        String membershipExpirationTmStr = "";
                        String oldValue = "";
                        String newValue = "";
                        if(customerDetailVO.getMembershipStartTm() != null){
                            membershipStartTmStr = DateUtil.formatDate(customerDetailVO.getMembershipStartTm(),"yyyy-MM-dd");
                            oldValue += membershipStartTmStr;
                        }
                        if(customerDetailVO.getMembershipExpirationTm() != null){
                            membershipExpirationTmStr = DateUtil.formatDate(customerDetailVO.getMembershipExpirationTm(),"yyyy-MM-dd");
                            if(!StringUtils.isBlank(oldValue)){
                                oldValue += "至" + membershipExpirationTmStr;
                            }else{
                                oldValue += membershipExpirationTmStr;
                            }
                        }

                        newValue += DateUtil.formatDate(membershipStartTm,"yyyy-MM-dd");
                        newValue += "至" + DateUtil.formatDate(membershipExpirationTm,"yyyy-MM-dd");
                        if(!oldValue.equals(newValue) ){
                            String logContent = getLogContent(userName,"将会员起止日期'",oldValue,newValue);
                            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(accountId,customerId,logType,logContent,logRemark);
                            workLogList.add(customerServiceWorkLog);
                        }
                    }
                }

                if(!customerUpdateQO.getUnifiedSocialCreditCode().equals(customerDetailVO.getUnifiedSocialCreditCode())){//修改了统一社会信用代码
                    String logContent = getLogContent(userName,"将统一社会信用代码'",customerDetailVO.getUnifiedSocialCreditCode(),customerUpdateQO.getUnifiedSocialCreditCode());
                    CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(accountId,customerId,logType,logContent,logRemark);
                    workLogList.add(customerServiceWorkLog);
                }
                if(!customerUpdateQO.getMemberErrorData().equals(customerDetailVO.getMemberErrorData())){//修改了数据状态
                    String logContent = getLogContent(userName,"将数据状态'", CustomerDataStatusEnum.getMessage(customerDetailVO.getMemberErrorData()),CustomerDataStatusEnum.getMessage(customerUpdateQO.getMemberErrorData()));
                    CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(accountId,customerId,logType,logContent,logRemark);
                    workLogList.add(customerServiceWorkLog);
                }
            }

            //8. 修改客户表(chs_customer)
            updateCustomer(customerUpdateQO,accountId);

            if(workLogList != null && workLogList.size() > 0){//日志集合不为空执行批量插入
                workLogService.insertWorkLogBatch(workLogList);
            }
            return true;
        }
        return false;
    }


    /**
     * 修改客户
     * @param customerUpdateQO  --客户修改信息
     * @param accountId         --当前操作人ID
     * @author yincuimei
     * @return
     */
    public Boolean updateCustomer(CustomerUpdateQO customerUpdateQO,String accountId){
        Customer customer =  new Customer();
        customer.setCustomerId(customerUpdateQO.getCustomerId());//客户ID
        customer.setUpdatePeopleId(accountId);//更新人ID
        customer.setUpdateTm(new Date());//更新时间
        customer.setCustomerName(customerUpdateQO.getCustomerName());//客户名称
        customer.setMembershipLevel(customerUpdateQO.getMembershipLevel());//会员等级
        customer.setMembershipStartTm(customerUpdateQO.getMembershipStartTm());//会员开始时间
        customer.setMembershipExpirationTm(customerUpdateQO.getMembershipExpirationTm());//会员截止时间
        customer.setUnifiedSocialCreditCode(customerUpdateQO.getUnifiedSocialCreditCode());//统一社会信用代码
        customer.setMemberErrorData(customerUpdateQO.getMemberErrorData());//数据状态
        if(StringUtils.isBlank(customerUpdateQO.getOwnerPeopleId())){ //客户所有人为空
            customer.setCurrentStatus((short) 0);//目前状态-未领取
            customer.setReceivePeopleId(null);//领取人ID置空
            customer.setAssignedPersonId(null);//分配人ID置空
            customer.setAccountId(null);//所有人ID置空
            customer.setOwnerId(null); //所有人ID置空
            customer.setCompanyName(null); //所属公司置空
            customerDbService.updateRetrieveCustomer(customer);
        }else{
            customer.setCompanyName(customerUpdateQO.getCompanyId());//所属分公司ID
            customer.setAccountId(customerUpdateQO.getOwnerPeopleId());//所有人ID
            customer.setOwnerId(customerUpdateQO.getOwnerPeopleId());//冗余字段维护
            customer.setCurrentStatus((short) 2);//设置为已分配
            customer.setAssignedPersonId(customerUpdateQO.getOwnerPeopleId());//被分配人ID
        }
        return customerDbService.updateCustomerByCustomerId(customer);
    }

    /**
     * 客户收回
     * @param customerId   --客户ID
     * @param returnReason --收回原因
     * @author yincuimei
     * @return
     */
    public Boolean retrieveCustomer(String accountId,String customerId, String returnReason) {
        Boolean result = false;
        //新增客户退回记录(chs_customer_return)
        result = customerReturnService.insertCustomerReturn(accountId, customerId, "1", returnReason);

        //根据客户ID更新商机所有人ID、分公司ID(sj_opportunity)
        result = opportunityDbService.updateOpportunityByCustomerId(customerId, "", "", accountId, new Date());

        //根据客户ID修改客户联系人表所属分公司ID(chs_customer_contact_person)
        CustomerContactPerson customerContactPerson = new CustomerContactPerson();
        customerContactPerson.setUpdatePeopleId(accountId);//所有人
        customerContactPerson.setCompanyId(null);//所属公司
        customerContactPerson.setUpdateTm(new Date());//更新时间
        result = contactPersonDbService.updateCustomerPersonByCustomerId(customerContactPerson,customerId);


        //根据客户ID更新联系人所有人ID、分公司ID(lxr_contact)
        result = contactDbService.updateContactByCustomerId(customerId, "", "", accountId, new Date());
        return result;
    }

    /**
     * 日志内容
     * @param userName  --操作人名
     * @param type      --操作内容类型
     * @param oldValue  --原值
     * @param newValue  --新值
     * @author yincuimei
     * @return
     */
    public String getLogContent(String userName,String type,String oldValue,String newValue){
        if(StringUtils.isBlank(oldValue) || "请选择".equals(oldValue)){
            oldValue = "空";
        }
        if(StringUtils.isBlank(newValue) || "请选择".equals(newValue)){
            newValue = "空";
        }
        return userName + type + oldValue + "'改为" + newValue;
    }


    /**
     * (客服部)客户列表--操作解锁
     * @param customerId 客户ID
     * @param remarks  备注
     * @param customerName 客户名称
     * @author wangpeng
     * @return
     */
    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public Boolean updateCustomerMembershipLevelUnlock(String customerId,String remarks,String customerName) {
        //获取当前登录人
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        String accountId = userAccount.getAccountId();
        String userName = userAccount.getUserName();
        //日志类型
        short logType = WorkLogEnum.LOG_TYPE_CUSTOMER.getCode().shortValue();
        //工作内容  登录人+客户名称+解锁
        String logContent = userName+"将"+customerName+"解锁";
        //备注   备注信息+操作人
        String logremarks =   remarks+"  "+ userName;
        //新增工作日志(csd_work_log)
        CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(accountId,customerId,logType,logContent,logremarks);
        workLogService.insertWorkLog(customerServiceWorkLog);
        return customerDbService.updateCustomerMembershipLevelUnlock(customerId);
    }

    /**
     * (客服部)客户列表--操作锁定
     * @param customerId 客户ID
     * @param remarks  备注
     * @param customerName 客户名称
     * @author wangpeng
     * @return
     */
    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public Boolean updateCustomerMembershipLevelLocking(String customerId,String remarks,String customerName) {
        //获取当前登录人
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        String accountId = userAccount.getAccountId();
        String userName = userAccount.getUserName();
        //日志类型
        short logType = WorkLogEnum.LOG_TYPE_CUSTOMER.getCode().shortValue();
        //工作内容  登录人+客户名称+锁定
        String logContent = userName+"将"+customerName+"锁定";
        //备注   备注信息+操作人
        String logremarks =   remarks+"  "+ userName;
        //新增工作日志(csd_work_log)
        CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(accountId,customerId,logType,logContent,logremarks);
        workLogService.insertWorkLog(customerServiceWorkLog);
        return  customerDbService.updateCustomerMembershipLevelLocking(customerId);
    }

    /**
     * 会员卡详情
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public CustomerMemberCardDetailVO selectCustomerCardDetail(String customerProductDetailMemberCardId,String memberCardNumber) {
        //会员卡详细信息
        CustomerMemberCardDetailVO customerMemberCardDetailVO = customerMemberCardDetailDbService.selectCustomerCardDetail(customerProductDetailMemberCardId);
        return customerMemberCardDetailVO;
    }

    public void updateCardDetail(String customerProductDetailMemberCardId) {

        UserAccount user = (UserAccount) SecurityUtils.getSubject().getPrincipal();

        //服务明细
        CustomerMemberCardDetail customerMemberCardDetail = customerMemberCardDetailDbService.selectCustomerMemberCardDetail(customerProductDetailMemberCardId);
        if(customerMemberCardDetail != null){
            customerMemberCardDetail.setDeleteStatus(Short.parseShort(String.valueOf(StatusCodeEnum.DELETE_CODE.getState())));
            customerMemberCardDetail.setUpdatePeopleId(user.getAccountId());
            customerMemberCardDetail.setUpdateTm(new Date());
            customerMemberCardDetailDbService.updateCustomerMemberCardDetail(customerMemberCardDetail);

            //刷卡记录
            List<CustomerMemberCardDetailSwipingRecord> swipingList = customerMemberCardDetailDbService.selectCustomerMemberCardDetailSwipingRecord(customerProductDetailMemberCardId);
            if(swipingList != null && swipingList.size() > 0){
                for(CustomerMemberCardDetailSwipingRecord skjl : swipingList) {
                    skjl.setDeleteStatus(Short.parseShort(String.valueOf(StatusCodeEnum.DELETE_CODE.getState())));
                    skjl.setUpdatePeopleId(user.getAccountId());
                    skjl.setUpdateTm(new Date());
                    customerMemberCardDetailDbService.updateCustomerMemberCardDetailSwipingRecord(skjl);
                }
            }

            //视频观看记录
            List<CustomerMemberCardDetailVideoViewingRecord> videoList = customerMemberCardDetailDbService.selectCustomerMemberCardDetailVideoViewingRecord(customerProductDetailMemberCardId);
            if(videoList != null && videoList.size() > 0){
                for(CustomerMemberCardDetailVideoViewingRecord video : videoList) {
                    video.setDeleteStatus(Short.parseShort(String.valueOf(StatusCodeEnum.DELETE_CODE.getState())));
                    video.setUpdatePeopleId(user.getAccountId());
                    video.setUpdateTm(new Date());
                    customerMemberCardDetailDbService.updateCustomerMemberCardDetailVideoViewingRecord(video);
                }
            }

            //电话答疑拨打记录
            List<CustomerMemberCardDetailPhoneAnsweringRecord> answerList = customerMemberCardDetailDbService.selectCustomerMemberCardDetailPhoneAnsweringRecord(customerProductDetailMemberCardId);
            if(answerList != null && answerList.size() > 0){
                for(CustomerMemberCardDetailPhoneAnsweringRecord dhdybd : answerList) {
                    dhdybd.setDeleteStatus(Short.parseShort(String.valueOf(StatusCodeEnum.DELETE_CODE.getState())));
                    dhdybd.setUpdatePeopleId(user.getAccountId());
                    dhdybd.setUpdateTm(new Date());
                    customerMemberCardDetailDbService.updateCustomerMemberCardDetailPhoneAnsweringRecord(dhdybd);
                }
            }

            //直播报名预约
            List<CustomerMemberCardDetailLiveSignatureAppointment> appointmentList =  customerMemberCardDetailDbService.selectCustomerMemberCardDetailLiveSignatureAppointment(customerProductDetailMemberCardId);
            if(appointmentList != null && appointmentList.size() > 0){
                for(CustomerMemberCardDetailLiveSignatureAppointment zbbmyy : appointmentList) {
                    zbbmyy.setDeleteStatus(Short.parseShort(String.valueOf(StatusCodeEnum.DELETE_CODE.getState())));
                    zbbmyy.setUpdatePeopleId(user.getAccountId());
                    zbbmyy.setUpdateTm(new Date());
                    customerMemberCardDetailDbService.updateCustomerMemberCardDetailLiveSignatureAppointment(zbbmyy);
                }
            }

            //直播购买记录
            List<CustomerMemberCardDetailLivePurchaseRecord> purchaseList = customerMemberCardDetailDbService.selectCustomerMemberCardDetailLivePurchaseRecord(customerProductDetailMemberCardId);
            if(purchaseList != null && purchaseList.size() > 0){
                for(CustomerMemberCardDetailLivePurchaseRecord zbgmjl : purchaseList) {
                    zbgmjl.setDeleteStatus(Short.parseShort(String.valueOf(StatusCodeEnum.DELETE_CODE.getState())));
                    zbgmjl.setUpdatePeopleId(user.getAccountId());
                    zbgmjl.setUpdateTm(new Date());
                    customerMemberCardDetailDbService.updateCustomerMemberCardDetailLivePurchaseRecord(zbgmjl);
                }
            }

            //点播购买记录
            List<CustomerMemberCardDetailDemandPurchaseRecord> demandList = customerMemberCardDetailDbService.selectCustomerMemberCardDetailDemandPurchaseRecord(customerProductDetailMemberCardId);
            if(demandList != null && demandList.size() > 0){
                for(CustomerMemberCardDetailDemandPurchaseRecord dbgmjl : demandList) {
                    dbgmjl.setDeleteStatus(Short.parseShort(String.valueOf(StatusCodeEnum.DELETE_CODE.getState())));
                    dbgmjl.setUpdatePeopleId(user.getAccountId());
                    dbgmjl.setUpdateTm(new Date());
                    customerMemberCardDetailDbService.updateCustomerMemberCardDetailDemandPurchaseRecord(dbgmjl);
                }
            }
        }


    }

    /**
     * 客户详情-会员卡详情
     * @param customerProductDetailMemberCardId 会员卡id
     * @param memberCardNumber 会员卡号
     * @author baijian
     * @return
     */
    @Override
    public void customerCardDetail(String customerProductDetailMemberCardId, String memberCardNumber) {
        updateCardDetail(customerProductDetailMemberCardId);
        expensesRecord(memberCardNumber,customerProductDetailMemberCardId);
        getCardFrequency(memberCardNumber,customerProductDetailMemberCardId);
    }

    /**
     * 客户详情-会员卡详情-修改合同的联系人姓名和联系方式
     * @param contractId 合同id
     * @author baijian
     * @return
     */
    @Override
    public Boolean updateContractNameAndPhone(String customerProductDetailMemberCardId,String contractId,
                                              String contactName,String contactDetails,
                                              String startTm,String endTm) {


        Boolean bs = true;
        UserAccount user = (UserAccount) SecurityUtils.getSubject().getPrincipal();

        CustomerMemberCardDetailVO vo = customerProductDetailMemberCardDbService.selectCustomerCard(customerProductDetailMemberCardId);


        CustomerProductDetailMemberCard card = customerProductDetailMemberCardDbService.selectById(customerProductDetailMemberCardId);


        String customerId = card.getCustomerId();

        List<CustomerServiceWorkLog> workLogList = new ArrayList<CustomerServiceWorkLog>();
        Short logType = WorkLogEnum.LOG_TYPE_MEMBERSHIP_CARD.getCode().shortValue();//日志类型
        String memberCardNumber = card.getMemberCardNumber();
        if(!StringUtils.isBlank(card.getContactName())) {
            if(!contactName.equals(card.getContactName())) {
                String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的联系人'"+card.getContactName()+"'改为"+contactName;
                CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
                workLogList.add(customerServiceWorkLog);
            }
        }else{
            String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的联系人''改为"+contactName;
            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
            workLogList.add(customerServiceWorkLog);
        }
        if(!StringUtils.isBlank(card.getPhone())) {
            if(!contactDetails.equals(card.getPhone())) {
                String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的联系方式'"+card.getPhone()+"'改为"+contactDetails;
                CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
                workLogList.add(customerServiceWorkLog);
            }
        }else{
            String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】联系方式''改为"+contactDetails;
            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
            workLogList.add(customerServiceWorkLog);
        }

        //开始时间
        if(!StringUtils.isBlank(vo.getStartTm()) && !StringUtils.isBlank(startTm)) {
            if(!startTm.equals(vo.getStartTm())) {
                String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的开始时间'"+vo.getStartTm()+"'改为"+startTm;
                CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
                workLogList.add(customerServiceWorkLog);
            }
        }else{
            if(!StringUtils.isBlank(vo.getStartTm())) {
                if(!vo.getStartTm().equals(startTm)) {
                    String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的开始时间'"+vo.getStartTm()+"'改为''";
                    CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
                    workLogList.add(customerServiceWorkLog);
                }
            }
            if(!StringUtils.isBlank(startTm)) {
                if(!startTm.equals(vo.getStartTm())) {
                    String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的开始时间''改为"+startTm;
                    CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
                    workLogList.add(customerServiceWorkLog);
                }
            }
        }

        //结束时间
        if(!StringUtils.isBlank(vo.getEndTm()) && !StringUtils.isBlank(endTm)) {
            if(!endTm.equals(vo.getEndTm())) {
                String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的结束时间'"+vo.getEndTm()+"'改为"+endTm;
                CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
                workLogList.add(customerServiceWorkLog);
            }
        }else{
            if(!StringUtils.isBlank(vo.getEndTm())) {
                if(!vo.getEndTm().equals(endTm)) {
                    String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的结束时间'"+vo.getEndTm()+"'改为''";
                    CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
                    workLogList.add(customerServiceWorkLog);
                }
            }
            if(!StringUtils.isBlank(endTm)) {
                if(!endTm.equals(vo.getEndTm())) {
                    String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的结束时间''改为"+endTm;
                    CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
                    workLogList.add(customerServiceWorkLog);
                }
            }
        }

        if(workLogList != null && workLogList.size() > 0){//日志集合不为空执行批量插入
            bs = workLogService.insertWorkLogBatch(workLogList);
        }

        vo.setCustomerProductDetailMemberCardId(customerProductDetailMemberCardId);
        vo.setContactName(contactName);
        vo.setContactDetails(contactDetails);
        if(!StringUtils.isBlank(startTm)){
            vo.setStartTm(startTm);
        }else{
            vo.setStartTm(null);
        }

        if(!StringUtils.isBlank(endTm)) {
            vo.setEndTm(endTm);
        }else{
            vo.setEndTm(null);
        }
        vo.setUpdateTm(new Date());
        vo.setUpdatePeopleId(user.getAccountId());
        customerProductDetailMemberCardDbService.updateCardXml(vo);

        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("phone", contactDetails);
        paramMap.put("card", card.getMemberCardNumber());
        paramMap.put("contactName", contactName);
        paramMap.put("type", 1);
        log.info("请求数据---"+paramMap);
        String res= HttpUtil.post("https://api.nsrjlb.com/crm/MemCard/setMemberCartPhone", paramMap);
        log.info("返回数据---"+res);

        return bs;
    }

    /**
     * 客户详情-会员卡详情-修改会员卡服务明细
     * @param customerMemberCardDetail 服务明细
     * @author baijian
     * @return
     */
    @Override
    public Boolean updateCustomerMemberCardDetail(MemberCardDetailVO customerMemberCardDetail) {

        CustomerMemberCardDetail detail = customerMemberCardDetailDbService.selectCustomerMemberCardDetail(customerMemberCardDetail.getCustomerProductDetailMemberCardId());

        CustomerProductDetailMemberCard customerProductDetailMemberCard = customerProductDetailMemberCardDbService.selectById(customerMemberCardDetail.getCustomerProductDetailMemberCardId());

        //Boolean bs = false;

        UserAccount user = (UserAccount) SecurityUtils.getSubject().getPrincipal();

        SysCompany sysCompany = sysCompanyDbService.selectSysCompanyById(user.getCompanyId());

        CustomerMemberCardDetail d = new CustomerMemberCardDetail();
        d.setDetailId(customerMemberCardDetail.getDetailId());
        d.setXcch(customerMemberCardDetail.getXcch());
        d.setHyhsycs(customerMemberCardDetail.getHyhsycs());
        d.setMinutes(customerMemberCardDetail.getMinutes());
        d.setLivePoints(customerMemberCardDetail.getLivePoints());
        d.setRemarks(customerMemberCardDetail.getRemarks());
        d.setUpdateTm(new Date());
        d.setUpdatePeopleId(user.getAccountId());
        customerMemberCardDetailDbService.updateCustomerMemberCardDetail(d);

        //调用crm系统扣次
        HashMap<String, Object> paramMap = new HashMap<>();
        String memberCardNumber = customerMemberCardDetail.getMemberCardNumber();
        paramMap.put("card", memberCardNumber);
        paramMap.put("num1", customerMemberCardDetail.getXcch());
        paramMap.put("num7", customerMemberCardDetail.getHyhsycs());
        paramMap.put("kmcs", customerMemberCardDetail.getLivePoints());
        paramMap.put("vtime", customerMemberCardDetail.getMinutes());
        paramMap.put("pid", sysCompany.getCompanyCode());
        paramMap.put("pname", sysCompany.getCompanyName());
        paramMap.put("tuname", user.getUserName());
        paramMap.put("remarks",customerMemberCardDetail.getRemarks());
        log.info("请求数据---"+paramMap);
        String res= HttpUtil.post("http://api.nsrjlb.com/crm/MemCard/memberCardDeductionForCrm", paramMap);
        log.info("返回数据---"+res);
        JSONObject json = JSON.parseObject(res);
        Integer de = json.getInteger("code");

        String customerId = customerProductDetailMemberCard.getCustomerId();

        List<CustomerServiceWorkLog> workLogList = new ArrayList<CustomerServiceWorkLog>();
        Short logType = WorkLogEnum.LOG_TYPE_MEMBERSHIP_CARD.getCode().shortValue();//日志类型



        //现场参会
        if(!customerMemberCardDetail.getXcch().equals(detail.getXcch())) {
            String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的现场参会'"+detail.getXcch()+"'改为"+customerMemberCardDetail.getXcch();
            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
            workLogList.add(customerServiceWorkLog);
        }

        //行业会剩余次数
        if(!customerMemberCardDetail.getHyhsycs().equals(detail.getHyhsycs())) {
            String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的行业会剩余次数'"+detail.getHyhsycs()+"'改为"+customerMemberCardDetail.getHyhsycs();
            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
            workLogList.add(customerServiceWorkLog);
        }

        //分钟数
        if(!customerMemberCardDetail.getMinutes().equals(detail.getMinutes())) {
            String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的分钟数'"+detail.getMinutes()+"'改为"+customerMemberCardDetail.getMinutes();
            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
            workLogList.add(customerServiceWorkLog);
        }

        //直播点数
        if(!customerMemberCardDetail.getLivePoints().equals(detail.getLivePoints())) {
            String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的直播点数'"+detail.getLivePoints()+"'改为"+customerMemberCardDetail.getLivePoints();
            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
            workLogList.add(customerServiceWorkLog);
        }

        //备注
        if(!customerMemberCardDetail.getRemarks().equals(detail.getRemarks())) {
            String logContent = user.getUserName()+"将会员卡号【"+memberCardNumber+"】的备注'"+detail.getRemarks()+"'改为"+customerMemberCardDetail.getRemarks();
            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
            workLogList.add(customerServiceWorkLog);
        }

        if(workLogList != null && workLogList.size() > 0){//日志集合不为空执行批量插入
            workLogService.insertWorkLogBatch(workLogList);
        }

        updateContractNameAndPhone(customerMemberCardDetail.getCustomerProductDetailMemberCardId(),null,customerMemberCardDetail.getContactName(),customerMemberCardDetail.getMobile(),"","");

        return true;
    }

    /**
     * (客服部)客户列表--客户详情-会员卡信息-作废会员卡
     * @param customerProductDetailMemberCard 会员卡id
     * @author yincuimei
     * @return
     */
    @Override
    public Boolean updateCustomerProductDetailMemberCard(CustomerProductDetailMemberCard customerProductDetailMemberCard) {
        UserAccount user = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        String customerId = customerProductDetailMemberCard.getCustomerId();

        List<CustomerServiceWorkLog> workLogList = new ArrayList<CustomerServiceWorkLog>();
        Short logType = WorkLogEnum.LOG_TYPE_PRODUCT.getCode().shortValue();//日志类型

        String newVoidStatus ="";
        String oldVoidStatus ="";
        Integer status =0;
        if(1 == customerProductDetailMemberCard.getVoidStatus()) {
            newVoidStatus = "作废";
            oldVoidStatus ="正常";
        }else{
            status = 1;
            newVoidStatus = "正常";
            oldVoidStatus ="作废";
        }

        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("type", 1);
        paramMap.put("card", customerProductDetailMemberCard.getMemberCardNumber());
        paramMap.put("status", status);
        log.info("请求数据---"+paramMap);
        String res= HttpUtil.post("https://api.nsrjlb.com/crm/MemCard/memberCardVoid", paramMap);
        log.info("返回数据---"+res);


        String logContent = user.getUserName()+"将会员卡号【"+customerProductDetailMemberCard.getMemberCardNumber() +"】状态'"+oldVoidStatus+"'改为"+newVoidStatus;
        CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
        workLogList.add(customerServiceWorkLog);

        if(workLogList != null && workLogList.size() > 0){//日志集合不为空执行批量插入
            workLogService.insertWorkLogBatch(workLogList);
        }




        customerProductDetailMemberCard.setUpdatePeopleId(user.getAccountId());
        customerProductDetailMemberCard.setUpdateTm(new Date());
        return customerSendCodeDbService.updateCustomerProductDetailMemberCard(customerProductDetailMemberCard);
    }

    /**
     * (客服部)客户列表--客户详情-产品信息-修改产品
     * @param finishOrderProduct 产品
     * @author yincuimei
     * @return
     */
    @Override
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    public Boolean updateFinishOrderProduct(FinishOrderProduct finishOrderProduct,String logRemark) {

        Boolean bs = false;

        FinishOrderProduct finsh = finishOrderProductDbService.selectFinishOrderProductById(finishOrderProduct.getFinishOrderProductId());

        UserAccount user = (UserAccount) SecurityUtils.getSubject().getPrincipal();

        CustomerProductOrderVO order = customerProductOrderDbService.selectOrderByNumber(finsh.getOrderNumber());
        String customerId = order.getCustomerId();

        List<CustomerServiceWorkLog> workLogList = new ArrayList<CustomerServiceWorkLog>();
        Short logType = WorkLogEnum.LOG_TYPE_PRODUCT.getCode().shortValue();//日志类型


//        //成交价
//        if(finsh.getProductFinalPrice() == null) {
//            finsh.setProductFinalPrice(new BigDecimal("0.00"));
//        }
//        if(finishOrderProduct.getProductFinalPrice() == null) {
//            finishOrderProduct.setProductFinalPrice(new BigDecimal("0.00"));
//        }
//        if(finishOrderProduct.getProductFinalPrice().compareTo(finsh.getProductFinalPrice()) != 0) {
//            String logContent = user.getUserName()+"将【订单编号"+finsh.getOrderNumber() +",产品号"+finsh.getFinishOrderProductNum()+"】的成交价\""+finsh.getProductFinalPrice()+"\"改为"+finishOrderProduct.getProductFinalPrice();
//            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,logRemark);
//            workLogList.add(customerServiceWorkLog);
//        }
//
//        //产品拆分后成交价
//        if(finsh.getProductPartFinalPrice() == null) {
//            finsh.setProductPartFinalPrice(new BigDecimal("0.00"));
//        }
//        if(finishOrderProduct.getProductPartFinalPrice() == null) {
//            finishOrderProduct.setProductPartFinalPrice(new BigDecimal("0.00"));
//        }
//        if(finishOrderProduct.getProductPartFinalPrice().compareTo(finsh.getProductPartFinalPrice()) != 0 ) {
//            String logContent = user.getUserName()+"【将订单编号"+finsh.getOrderNumber() +",产品号"+finsh.getFinishOrderProductNum()+"】的产品拆分后成交价\""+finsh.getProductPartFinalPrice()+"\"改为"+finishOrderProduct.getProductPartFinalPrice();
//            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,logRemark);
//            workLogList.add(customerServiceWorkLog);
//        }

        //业绩金额
//        if(finsh.getGradeMoney() == null) {
//            finsh.setGradeMoney(new BigDecimal("0.00"));
//        }
//        if(finishOrderProduct.getGradeMoney() == null) {
//            finishOrderProduct.setGradeMoney(new BigDecimal("0.00"));
//        }
//        if(finishOrderProduct.getGradeMoney().compareTo(finsh.getGradeMoney()) != 0) {
//            String logContent = user.getUserName()+"将订单编号"+finsh.getOrderNumber() +",产品号"+finsh.getFinishOrderProductNum()+"业绩金额'"+finsh.getGradeMoney()+"'改为"+finishOrderProduct.getGradeMoney();
//            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
//            workLogList.add(customerServiceWorkLog);
//        }
//
//        //拆分后业绩金额
//        if(finsh.getPartGradeMoney() == null) {
//            finsh.setPartGradeMoney(new BigDecimal("0.00"));
//        }
//        if(finishOrderProduct.getPartGradeMoney() == null) {
//            finishOrderProduct.setPartGradeMoney(new BigDecimal("0.00"));
//        }
//        if(finishOrderProduct.getPartGradeMoney().compareTo(finsh.getPartGradeMoney()) != 0) {
//            String logContent = user.getUserName()+"将订单编号"+finsh.getOrderNumber() +",产品号"+finsh.getFinishOrderProductNum()+"拆分后业绩金额'"+finsh.getPartGradeMoney()+"'改为"+finishOrderProduct.getPartGradeMoney();
//            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,null);
//            workLogList.add(customerServiceWorkLog);
//        }
//        String newStatus = "退款";
//        if("0".equals(finishOrderProduct.getProductStatus())) {
//            newStatus = "正常";
//        }
//        String oldStatus = "退款";
//        if("0".equals(finsh.getProductStatus())) {
//            oldStatus = "正常";
//        }

        String oldProductStatus = FinishOrderProductEnum.getProductStatusText(finsh.getProductStatus());
        String newProductStatus = FinishOrderProductEnum.getProductStatusText(finishOrderProduct.getProductStatus());
        //产品状态(只有产品状态为已回款的才可修改)
        if(!finishOrderProduct.getProductStatus().equals(finsh.getProductStatus()) && "3".equals(finsh.getProductStatus())) {
            String logContent = user.getUserName()+"将【订单编号"+finsh.getOrderNumber() +",产品号"+finsh.getFinishOrderProductNum()+"】的产品状态\""+oldProductStatus+"\"改为"+newProductStatus;
            CustomerServiceWorkLog customerServiceWorkLog = workLogService.getCustomerServiceWorkLog(user.getAccountId(),customerId,logType,logContent,logRemark);
            workLogList.add(customerServiceWorkLog);
            finishOrderProduct.setUpdatePeopleId(user.getAccountId());
            finishOrderProduct.setUpdateTm(new Date());
            bs = finishOrderProductDbService.updateFinishOrderProduct(finishOrderProduct);
        }

        if(workLogList != null && workLogList.size() > 0){//日志集合不为空执行批量插入
            bs = workLogService.insertWorkLogBatch(workLogList);
        }

        return bs;
    }

    /**
     * selectCustomerInfoList
     * @Author wangpeng
     * @Date 2021/9/27
     * @param customerQO
     * @param pageIndex
     * @param pageSize
     * @param sortName
     * @param sortOrder
     * @return
     */
    @Override
    public DhPageInfo<CustomerInfoVO> selectCustomerInfoList(CustomerInfoQO customerQO, Integer pageIndex, Integer pageSize, String sortName, String sortOrder) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        //排序
        StringBuilder order = new StringBuilder();
        if (!StringUtils.isBlank(sortName) && !StringUtils.isBlank(sortOrder)) {
            switch (sortName) {
                case "createTm": {
                    order.append(" t.create_time ").append(sortOrder);//创建时间
                }
                break;
                default:
                    break;
            }
        }
        List<CustomerInfoVO> customerVOList = customerDbService.selectCustomerInfoList(customerQO,order.toString());
        PageInfo<CustomerInfoVO> pageInfo = new PageInfo<CustomerInfoVO>(customerVOList);
        return new DhPageInfo<CustomerInfoVO>(pageInfo, customerVOList);
    }

    /**
     * uploadExcel
     * @Author wangpeng
     * @Date 2021/10/12
     * @param list
     * @return
     */
    @Override
    public JSONObject uploadExcel(List<ImportCustomerInfoVO> list){
        //返回的结果集
        JSONObject jsonObject = new JSONObject();
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        String userAccountId = userAccount.getAccountId();

        List<CustomerInfo> insertList = new ArrayList<CustomerInfo>();
        list.forEach(importCustomerInfoVO -> {
            CustomerInfo customerInfo = new CustomerInfo();
            customerInfo.setCustomerInfoId(CommonUtils.getGUID());
            customerInfo.setCreateTime(new Date());
            customerInfo.setCreatePeopleId(userAccountId);
            customerInfo.setDeleteStatus(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
            BeanUtils.copyProperties(importCustomerInfoVO,customerInfo);
            insertList.add(customerInfo);
        });
        customerDbService.addCustomerInfo(insertList);
        jsonObject.put("code", 0);
        jsonObject.put("msg", "成功");
        return jsonObject;
    }

    /**
     * exportExcel
     * @Author wangpeng
     * @Date 2021/10/12
     * @param 	
     * @return
     */
    @Override
    public List<ImportCustomerInfoVO> exportExcel() {
        return customerDbService.exportExcel();
    }


    /**
     * 会员卡电话答疑拨打记录
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public DhPageInfo<CustomerMemberCardDetailPhoneAnsweringRecord> answerList(Integer pageIndex, Integer pageSize, String sortName, String sortOrder, String customerProductDetailMemberCardId) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        List<CustomerMemberCardDetailPhoneAnsweringRecord> list = customerMemberCardDetailDbService.selectCustomerMemberCardDetailPhoneAnsweringRecord(customerProductDetailMemberCardId);
        PageInfo<CustomerMemberCardDetailPhoneAnsweringRecord> pageInfo = new PageInfo<CustomerMemberCardDetailPhoneAnsweringRecord>(list);
        return new DhPageInfo<CustomerMemberCardDetailPhoneAnsweringRecord>(pageInfo, list);

    }

    /**
     * 会员卡视频观看记录
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public DhPageInfo<CustomerMemberCardDetailVideoViewingRecord> videoList(Integer pageIndex, Integer pageSize, String sortName, String sortOrder, String customerProductDetailMemberCardId) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        List<CustomerMemberCardDetailVideoViewingRecord> videoList = customerMemberCardDetailDbService.selectCustomerMemberCardDetailVideoViewingRecord(customerProductDetailMemberCardId);
        PageInfo<CustomerMemberCardDetailVideoViewingRecord> pageInfo = new PageInfo<CustomerMemberCardDetailVideoViewingRecord>(videoList);
        return new DhPageInfo<CustomerMemberCardDetailVideoViewingRecord>(pageInfo, videoList);
    }

    /**
     * 会员卡直播报名预约
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public DhPageInfo<CustomerMemberCardDetailLiveSignatureAppointment> appointmentList(Integer pageIndex, Integer pageSize, String sortName, String sortOrder, String customerProductDetailMemberCardId) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        List<CustomerMemberCardDetailLiveSignatureAppointment> appointmentList =  customerMemberCardDetailDbService.selectCustomerMemberCardDetailLiveSignatureAppointment(customerProductDetailMemberCardId);
        PageInfo<CustomerMemberCardDetailLiveSignatureAppointment> pageInfo = new PageInfo<CustomerMemberCardDetailLiveSignatureAppointment>(appointmentList);
        return new DhPageInfo<CustomerMemberCardDetailLiveSignatureAppointment>(pageInfo, appointmentList);
    }

    /**
     * 会员卡服务明细
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public MemberCardDetailVO customerMemberCardDetail(String customerProductDetailMemberCardId) {
        MemberCardDetailVO vo = customerMemberCardDetailDbService.selectMemberCardDetail(customerProductDetailMemberCardId);

        CustomerProductDetailMemberCard card = customerProductDetailMemberCardDbService.selectById(customerProductDetailMemberCardId);

        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("card", card.getMemberCardNumber());
        log.info("请求数据---"+paramMap);
        String res= HttpUtil.post("https://api.nsrjlb.com/crm/MemCard/getMemberCartForCrm", paramMap);
        log.info("返回数据---"+res);
        JSONObject json = JSON.parseObject(res);
        Integer de = json.getInteger("code");
        if (de != null && de == 1) {
            JSONObject jsonObj = json.getJSONObject("data");//获取json数组中的data项
            String mobile = jsonObj.getString("mobile");
            String contactName = jsonObj.getString("contactName");
            vo.setContactName(contactName);
            vo.setMobile(mobile);
            card.setContactName(contactName);
            card.setPhone(mobile);
            card.setUpdateTm(new Date());
            customerProductDetailMemberCardDbService.updateCard(card);
        }
        return vo;
    }

    /**
     * 会员卡刷卡记录
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public DhPageInfo<CustomerMemberCardDetailSwipingRecord> swipingList(Integer pageIndex, Integer pageSize, String sortName, String sortOrder, String customerProductDetailMemberCardId) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        List<CustomerMemberCardDetailSwipingRecord> swipingList = customerMemberCardDetailDbService.selectCustomerMemberCardDetailSwipingRecord(customerProductDetailMemberCardId);
        PageInfo<CustomerMemberCardDetailSwipingRecord> pageInfo = new PageInfo<CustomerMemberCardDetailSwipingRecord>(swipingList);
        return new DhPageInfo<CustomerMemberCardDetailSwipingRecord>(pageInfo, swipingList);
    }

    /**
     * 会员卡直播购买记录
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public DhPageInfo<CustomerMemberCardDetailLivePurchaseRecord> purchaseList(Integer pageIndex, Integer pageSize, String sortName, String sortOrder, String customerProductDetailMemberCardId) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        List<CustomerMemberCardDetailLivePurchaseRecord> purchaseList = customerMemberCardDetailDbService.selectCustomerMemberCardDetailLivePurchaseRecord(customerProductDetailMemberCardId);
        PageInfo<CustomerMemberCardDetailLivePurchaseRecord> pageInfo = new PageInfo<CustomerMemberCardDetailLivePurchaseRecord>(purchaseList);
        return new DhPageInfo<CustomerMemberCardDetailLivePurchaseRecord>(pageInfo, purchaseList);
    }

    /**
     * 会员卡点播购买记录
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public DhPageInfo<CustomerMemberCardDetailDemandPurchaseRecord> demandList(Integer pageIndex, Integer pageSize, String sortName, String sortOrder, String customerProductDetailMemberCardId) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }

        List<CustomerMemberCardDetailDemandPurchaseRecord> demandList = customerMemberCardDetailDbService.selectCustomerMemberCardDetailDemandPurchaseRecord(customerProductDetailMemberCardId);
        PageInfo<CustomerMemberCardDetailDemandPurchaseRecord> pageInfo = new PageInfo<CustomerMemberCardDetailDemandPurchaseRecord>(demandList);
        return new DhPageInfo<CustomerMemberCardDetailDemandPurchaseRecord>(pageInfo, demandList);
    }

    /**
     * 消费记录
     * @param memberCardNumber 会员卡号
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     */
    public void expensesRecord(String memberCardNumber,String customerProductDetailMemberCardId) {
        UserAccount user = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("code", memberCardNumber);
        log.info("请求数据---"+paramMap);
        String res= HttpUtil.post("http://api.nsrjlb.com/crm/memCard/expensesRecord", paramMap);
        log.info("返回数据---"+res);
        JSONObject json = JSON.parseObject(res);
        Integer de = json.getInteger("code");
        if (de != null && de == 1) {
            JSONObject jsonObj = json.getJSONObject("data");//获取json数组中的data项

            //会员卡刷卡记录
            String memberCardCredit = jsonObj.getString("memberCardCredit");
            if (!StringUtils.isBlank(memberCardCredit)) {
                List<CustomerMemberCardCreditVO> exList = JSONArray.parseArray(memberCardCredit, CustomerMemberCardCreditVO.class);
                for (CustomerMemberCardCreditVO credit : exList) {
                    CustomerMemberCardDetailSwipingRecord swiping = new CustomerMemberCardDetailSwipingRecord();
                    swiping.setSwipingRecordId(CommonUtils.getGUID());
                    swiping.setName(credit.getName());
                    swiping.setQuantity(credit.getCs());
                    swiping.setSwipingDate(credit.getSkdate());
                    swiping.setCategory(credit.getLeibie());
                    swiping.setCourseName(credit.getKname());
                    swiping.setRemarks(credit.getBeizhu());
                    swiping.setCreatePeopleId(user.getAccountId());
                    swiping.setCreateTm(new Date());
                    swiping.setUpdatePeopleId(user.getAccountId());
                    swiping.setUpdateTm(new Date());
                    swiping.setMemberCardNumber(memberCardNumber);
                    swiping.setCustomerProductDetailMemberCardId(customerProductDetailMemberCardId);
                    customerMemberCardDetailDbService.addCustomerMemberCardDetailSwipingRecord(swiping);
                }
            }

            //视频观看记录
            String videoViewingRecord = jsonObj.getString("videoViewingRecord");
            if (!StringUtils.isBlank(videoViewingRecord)) {
                List<VideoViewingRecordVO> exList = JSONArray.parseArray(videoViewingRecord, VideoViewingRecordVO.class);
                for (VideoViewingRecordVO videoViewingRecordVO : exList) {
                    CustomerMemberCardDetailVideoViewingRecord video = new CustomerMemberCardDetailVideoViewingRecord();
                    video.setVideoViewingRecordId(CommonUtils.getGUID());
                    video.setVideoViewingDate(videoViewingRecordVO.getLogAddtime());
                    video.setCourseName(videoViewingRecordVO.getLogActivity());
                    video.setCreatePeopleId(user.getAccountId());
                    video.setCreateTm(new Date());
                    video.setUpdatePeopleId(user.getAccountId());
                    video.setUpdateTm(new Date());
                    video.setMemberCardNumber(memberCardNumber);
                    video.setCustomerProductDetailMemberCardId(customerProductDetailMemberCardId);
                    customerMemberCardDetailDbService.addCustomerMemberCardDetailVideoViewingRecord(video);
                }
            }

            //用户答疑数量
            String userQuantity = jsonObj.getString("userQuantity");
            CustomerMemberCardDetail customerMemberCardDetail = new CustomerMemberCardDetail();
            customerMemberCardDetail.setDetailId(CommonUtils.getGUID());
            customerMemberCardDetail.setUserquantity(userQuantity);
            customerMemberCardDetail.setCreatePeopleId(user.getAccountId());
            customerMemberCardDetail.setCreateTm(new Date());
            customerMemberCardDetail.setUpdatePeopleId(user.getAccountId());
            customerMemberCardDetail.setUpdateTm(new Date());
            customerMemberCardDetail.setMemberCardNumber(memberCardNumber);
            customerMemberCardDetail.setCustomerProductDetailMemberCardId(customerProductDetailMemberCardId);
            customerMemberCardDetailDbService.addCustomerMemberCardDetail(customerMemberCardDetail);

            //电话答疑拨打记录
            String phoneAnsweringRecord = jsonObj.getString("phoneAnsweringRecord");
            if (!StringUtils.isBlank(phoneAnsweringRecord)) {
                List<PhoneAnsweringRecordVO> exList = JSONArray.parseArray(phoneAnsweringRecord, PhoneAnsweringRecordVO.class);
                for (PhoneAnsweringRecordVO vo : exList) {
                    CustomerMemberCardDetailPhoneAnsweringRecord phoneAnswering = new CustomerMemberCardDetailPhoneAnsweringRecord();
                    phoneAnswering.setPhoneAnsweringRecordId(CommonUtils.getGUID());
                    phoneAnswering.setPhoneAnsweringDate(vo.getTjsj());
                    phoneAnswering.setAbstracts(vo.getZxnr());
                    phoneAnswering.setCreatePeopleId(user.getAccountId());
                    phoneAnswering.setCreateTm(new Date());
                    phoneAnswering.setUpdatePeopleId(user.getAccountId());
                    phoneAnswering.setUpdateTm(new Date());
                    phoneAnswering.setMemberCardNumber(memberCardNumber);
                    phoneAnswering.setCustomerProductDetailMemberCardId(customerProductDetailMemberCardId);
                    customerMemberCardDetailDbService.addCustomerMemberCardDetailPhoneAnsweringRecord(phoneAnswering);
                }
            }

            //直播报名预约
            String liveSignatureAppointment = jsonObj.getString("liveSignatureAppointment");
            if (!StringUtils.isBlank(liveSignatureAppointment)) {
                List<LiveSignatureAppointmentVO> exList = JSONArray.parseArray(liveSignatureAppointment, LiveSignatureAppointmentVO.class);
                for (LiveSignatureAppointmentVO vo : exList) {
                    CustomerMemberCardDetailLiveSignatureAppointment appointment = new CustomerMemberCardDetailLiveSignatureAppointment();
                    appointment.setLiveSignatureAppointmentId(CommonUtils.getGUID());
                    appointment.setAppointmentDate(vo.getDatime());
                    appointment.setNumber(vo.getVid());
                    appointment.setCreatePeopleId(user.getAccountId());
                    appointment.setCreateTm(new Date());
                    appointment.setUpdatePeopleId(user.getAccountId());
                    appointment.setUpdateTm(new Date());
                    appointment.setMemberCardNumber(memberCardNumber);
                    appointment.setCustomerProductDetailMemberCardId(customerProductDetailMemberCardId);
                    customerMemberCardDetailDbService.addCustomerMemberCardDetailLiveSignatureAppointment(appointment);
                }
            }


            JSONObject livePurchaseRecord = jsonObj.getJSONObject("livePurchaseRecord");//获取json数组中的data项
            String zhibo = livePurchaseRecord.getString("zhibo");
            String dianbo = livePurchaseRecord.getString("dianbo");

            //直播购买记录
            if (!StringUtils.isBlank(zhibo)) {
                List<LiveZbRecordVO> exList = JSONArray.parseArray(zhibo, LiveZbRecordVO.class);
                for (LiveZbRecordVO vo : exList) {
                    CustomerMemberCardDetailLivePurchaseRecord zb = new CustomerMemberCardDetailLivePurchaseRecord();
                    zb.setLivePurchaseRecordId(CommonUtils.getGUID());
                    zb.setDatime(vo.getDatime());
                    zb.setUid(vo.getUid());
                    zb.setVtitle(vo.getVtitle());
                    zb.setContent(vo.getContent());
                    zb.setAmount(vo.getAmount());
                    zb.setCreatePeopleId(user.getAccountId());
                    zb.setCreateTm(new Date());
                    zb.setUpdatePeopleId(user.getAccountId());
                    zb.setUpdateTm(new Date());
                    zb.setMemberCardNumber(memberCardNumber);
                    zb.setCustomerProductDetailMemberCardId(customerProductDetailMemberCardId);
                    customerMemberCardDetailDbService.addCustomerMemberCardDetailLivePurchaseRecord(zb);
                }
            }

            //点播购买记录
            if (!StringUtils.isBlank(dianbo)) {
                List<LiveDbRecordVO> exList = JSONArray.parseArray(dianbo, LiveDbRecordVO.class);
                for (LiveDbRecordVO vo : exList) {
                    CustomerMemberCardDetailDemandPurchaseRecord db = new CustomerMemberCardDetailDemandPurchaseRecord();
                    db.setDemandPurchaseRecordId(CommonUtils.getGUID());
                    db.setCourseId(vo.getVid());
                    db.setUid(vo.getUid());
                    db.setTitle(vo.getTitle());
                    db.setDatime(vo.getDatime());
                    db.setType(vo.getType());
                    db.setAmount(vo.getKnum());
                    db.setAuthor(vo.getAuthor());
                    db.setCreatePeopleId(user.getAccountId());
                    db.setCreateTm(new Date());
                    db.setUpdatePeopleId(user.getAccountId());
                    db.setUpdateTm(new Date());
                    db.setMemberCardNumber(memberCardNumber);
                    db.setCustomerProductDetailMemberCardId(customerProductDetailMemberCardId);
                    customerMemberCardDetailDbService.addCustomerMemberCardDetailDemandPurchaseRecord(db);
                }
            }


        }
    }

    /**
     * 会员卡次数查询
     * @param memberCardNumber 会员卡号
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     */
    public void getCardFrequency(String memberCardNumber,String customerProductDetailMemberCardId) {
        //UserAccount user = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        CustomerProductDetailMemberCard card = customerProductDetailMemberCardDbService.selectById(customerProductDetailMemberCardId);
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("card", memberCardNumber);
        log.info("请求数据---"+paramMap);
        String res= HttpUtil.post("http://api.nsrjlb.com/crm/MemCard/getCardFrequency", paramMap);
        log.info("返回数据---"+res);
        JSONObject json = JSON.parseObject(res);
        Integer de = json.getInteger("code");
        if (de != null && de == 1) {
            String data = json.getString("data");
            CardFrequencyVO vo = JSONArray.parseObject(data, CardFrequencyVO.class);
            CustomerMemberCardDetail customerMemberCardDetail = customerMemberCardDetailDbService.selectCustomerMemberCardDetail(customerProductDetailMemberCardId);
            if(customerMemberCardDetail != null) {
                customerMemberCardDetail.setXcch(vo.getNum1());
                customerMemberCardDetail.setHyhsycs(vo.getNum7());
                customerMemberCardDetail.setMinutes(vo.getVtime());
                customerMemberCardDetail.setLivePoints(vo.getKmcs());
                customerMemberCardDetail.setMobile(vo.getMobile());
                customerMemberCardDetail.setRemarks(vo.getRemarks());
                customerMemberCardDetailDbService.updateCustomerMemberCardDetail(customerMemberCardDetail);
            }else {
                customerMemberCardDetail = new CustomerMemberCardDetail();
                customerMemberCardDetail.setDetailId(CommonUtils.getGUID());
                customerMemberCardDetail.setXcch(vo.getNum1());
                customerMemberCardDetail.setHyhsycs(vo.getNum7());
                customerMemberCardDetail.setMinutes(vo.getVtime());
                customerMemberCardDetail.setLivePoints(vo.getKmcs());
                customerMemberCardDetail.setMobile(vo.getMobile());
                customerMemberCardDetail.setCreatePeopleId(card.getAccountId());
                customerMemberCardDetail.setCreateTm(new Date());
                customerMemberCardDetail.setUpdatePeopleId(card.getAccountId());
                customerMemberCardDetail.setUpdateTm(new Date());
                customerMemberCardDetail.setMemberCardNumber(memberCardNumber);
                customerMemberCardDetail.setCustomerProductDetailMemberCardId(customerProductDetailMemberCardId);
                customerMemberCardDetailDbService.addCustomerMemberCardDetail(customerMemberCardDetail);
            }


        }
    }


    /**
     * 客服部-客户信息库新增
     * @param customerInfoQO
     * @return
     */
    @Override
    public boolean addCustomerInfo(CustomerInfoQO customerInfoQO) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        CustomerInfo customerInfo = new CustomerInfo();
        BeanUtils.copyProperties(customerInfoQO,customerInfo);
        List<CustomerInfo> list = new ArrayList<CustomerInfo>();
        customerInfo.setCustomerInfoId(CommonUtils.getGUID());
        customerInfo.setCreateTime(new Date());
        customerInfo.setCreatePeopleId(userAccount.getAccountId());
        customerInfo.setDeleteStatus(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        list.add(customerInfo);
        customerDbService.addCustomerInfo(list);
        return true;
    }

    @Override
    public List<CustomerInfoVO> selectProviceList() {
        return customerDbService.selectProviceList();
    }

    @Override
    public List<CustomerInfoVO> selectCityByProvice(String provice) {
        return customerDbService.selectCityByProvice(provice);
    }

    @Override
    public List<CustomerInfoVO> selectDistrictByProviceCity(String provice, String city) {
        return customerDbService.selectDistrictByProviceCity(provice,city);
    }

    @Override
    public List<CustomerInfoVO> selectIndustryTypeList() {
        return customerDbService.selectIndustryTypeList();
    }

    @Override
    public CustomerInfo getCustomerInfoDetailByCustomerInfoId(String customerInfoId) {
        return customerDbService.getCustomerInfoDetailByCustomerInfoId(customerInfoId);
    }

    /**
     * 【客服部】客户信息库列表-详细-调整
     * @describe
     *    修改客户信息表(chs_customer_info:company_id;account_id)
     * @param customerInfoId --主键
     * @param companyId      --所属分公司
     * @param accountId      --所有人
     * @author yincuimei(2021-12-24)
     * @return
     */
    @Override
    public Boolean updateCompanyAndAccountById(String customerInfoId, String companyId, String accountId) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//当前登录人信息
        CustomerInfo customerInfo = null;
        if(!StringUtils.isBlank(customerInfoId)){
            customerInfo = new CustomerInfo();
            customerInfo.setCustomerInfoId(customerInfoId);//
            customerInfo.setUpdateTime(new Date());
            customerInfo.setUpdatePeopleId(userAccount.getAccountId());
            customerInfo.setCompanyId(companyId);
            customerInfo.setAccountId(accountId);
            return customerDbService.updateCompanyAndAccountById(customerInfo);
        }
        return false;
    }
}
